﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;

namespace TestRootBaseData.Service.Repository.Database
{
    class DbContextInitializer : DropCreateDatabaseIfModelChanges<RootBaseTestContext>
    {
        protected override void Seed(RootBaseTestContext context)
        {
            #region Configuration
            // ConfigurateAccount(context);
            #endregion

            #region Population
            Populate(context);
            #endregion
            base.Seed(context);
        }

        //example of sql script execution
        private static void ConfigurateAccount(RootBaseTestContext context)
        {

            string createUniqueIndexForAccountName =
                        @"CREATE UNIQUE NONCLUSTERED INDEX [IX_Account] ON [dbo].[Account] 
                        (
	                        [AccountName] ASC
                        )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
                        ";

            context.Database.ExecuteSqlCommand(createUniqueIndexForAccountName);
        }

        private static void Populate(RootBaseTestContext context)
        {
            //TechControlDomain.Model.SystemDomain domain1 = new Model.SystemDomain()
            //{
            //    SystemDomainID = new Guid("9D89BFAB-DBFB-4677-BBF2-F2423DF199E7"),
            //    SystemName = "RQC SYSTEM"

            //};
            //context.SystemDomains.Add(domain1);


            //TechControlDomain.Model.SystemDomain domain2 = new Model.SystemDomain()
            //{
            //    SystemDomainID = new Guid("902BE917-A15E-4050-B578-724BF91622A1"),
            //    SystemName = "CEM"

            //};

            //context.SystemDomains.Add(domain2);


            //context.SaveChanges();
        }
    }
}
